package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.BookingsBusinessAddDTO;
import org.jsola.hr.dto.BookingsBusinessUpdateDTO;
import org.jsola.hr.entity.BookingsBusinessDO;
import org.jsola.hr.query.BookingsBusinessQuery;
import org.jsola.hr.service.IBookingsBusinessService;
import org.jsola.hr.vo.BookingsBusinessVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 预约业务主表
 *
 * @author zhr
 */
@Component
public class BookingsBusinessTestHelper extends BaseTestHelper {
    
    @Autowired
    private IBookingsBusinessService bookingsBusinessService;

    /**
     * 生成add测试数据
     * @return BookingsBusinessAddDTO
     */
    public BookingsBusinessAddDTO getBookingsBusinessAddDTO(){
        BookingsBusinessAddDTO bookingsBusinessAddDTO = new BookingsBusinessAddDTO();
        bookingsBusinessAddDTO.setBookingsBusiness(getRandomValue("varchar",50));
        bookingsBusinessAddDTO.setServiceFall(getRandomValue("varchar",50));
        bookingsBusinessAddDTO.setBookingsCount(SafeKit.getInteger(getRandomValue("int",0)));
        bookingsBusinessAddDTO.setBookingsRemainingCount(SafeKit.getInteger(getRandomValue("int",0)));
        bookingsBusinessAddDTO.setBookingsBeginDate((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        bookingsBusinessAddDTO.setBookingsEndDate((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        bookingsBusinessAddDTO.setBusinessBeginDate((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        bookingsBusinessAddDTO.setBusinessEndDate((Date)ClassKit.getObjectValue(getRandomValue("date",0),"java.util.Date"));
        return bookingsBusinessAddDTO;
    }


    /**
     * 生成update测试数据
     * @return BookingsBusinessUpdateDTO
     */
    public BookingsBusinessUpdateDTO getBookingsBusinessUpdateDTO(BookingsBusinessVO bookingsBusinessVO){
        return bookingsBusinessService.selectDOById(bookingsBusinessVO.getId(), SITE_ID).to(BookingsBusinessUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return BookingsBusinessQuery
     */
    public BookingsBusinessQuery getBookingsBusinessQuery() {
        BookingsBusinessQuery bookingsBusinessQuery = new BookingsBusinessQuery();
        List<BookingsBusinessDO> bookingsBusinessDOList = bookingsBusinessService.list(new BookingsBusinessDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(bookingsBusinessDOList)) {
            BookingsBusinessDO bookingsBusinessDO = bookingsBusinessDOList.get(0);
            bookingsBusinessQuery = bookingsBusinessDO.to(BookingsBusinessQuery.class);
        }
        return bookingsBusinessQuery;
    }

    /**
     * 保存示例
     * @return BookingsBusinessVO
     */
    public BookingsBusinessVO saveBookingsBusinessExample(){
        BookingsBusinessAddDTO addDTO = this.getBookingsBusinessAddDTO();
        BookingsBusinessVO bookingsBusinessVO = bookingsBusinessService.save(addDTO,buildTokenUser());
        return bookingsBusinessVO;
    }


}

